/**
 * Created by lwy on 2017/8/11.
 */


var page = 1;

function doAjax() {
    $.ajax({
        url: '/crm/rechargeC/getAllRechargeRecord',
        dataType: 'json',
        data: {
            token: localStorage.getItem('crmtoken'),
            page: page,
            stateValue: $('#state').val(),
            payChannelValue: $('#payChannelValue').val(),
            code: $('#code').val(),
            userName: $('#userName').val(),
            transactionNo: $('#transactionNo').val(),
        },
        type: 'post',
        success: function (data) {
            if (data.code == -1) {
                window.parent.location.href = "/crm/login.jsp"
            }
            if (data.code == 0) {
                alert(data.msg);
            }
            if (data.code == 1) {
                $('#record').html(data.recordsTotal);
                $('#withdraw-record').empty();
                for (var i = 0; i < data.datas.length; i++) {

                    $('<tr class="gradeA odd">' +
                        '<td class="sorting_1 withdrawId">' + data.datas[i].id + '</td>' +
                        '<td class=" ">' + data.datas[i].userAccount + '</td>' +
                        '<td class=" ">' + data.datas[i].flux + '</td>' +
                        '<td class=" ">' + data.datas[i].money + '</td>' +
                        '<td class="center ">' + data.datas[i].payChannel + '</td>' +
                        '<td class="center ">' + data.datas[i].code + '</td>' +
                        '<td class="center ">' + data.datas[i].transactionNo + '</td>' +
                        '<td class="sorting_1">' + data.datas[i].createTime + '</td>' +
                        '<td class=" ">' + data.datas[i].payTime + '</td>' +
                        '<td class=" ">' + data.datas[i].cancleTime + '</td>' +
                        '<td class="center ">' + data.datas[i].state + '</td>' +
                        '<td class="mdvalueAddedServices" style="text-decoration: underline;cursor: pointer;" id="' + data.datas[i].id + '">处理</td>' +
                        '</tr>').appendTo($('#withdraw-record'));
                }
                $('.mdvalueAddedServices').click(function () {
                    if (window.confirm('你确定已经充值过了吗？')) {
                        //alert("确定");
                        var applyId = $(this).attr('id');
                        $.ajax({
                            url: '/crm/rechargeC/dispose.json',
                            dataType: 'json',
                            data: {
                                token: localStorage.getItem('crmtoken'),
                                id: applyId
                            },
                            type: 'post',
                            success: function (data) {
                                if (data.code == -1) {
                                    window.parent.location.href = "/crm/login.jsp"
                                }
                                if (data.code == 0) {
                                    alert(data.msg);
                                }
                                if (data.code == 1) {
                                    alert("已处理！")
                                    doAjax()
                                }
                            }
                        })
                        return true;
                    } else {
                        //alert("取消");
                        return false;
                    }

                })


                $(".pagination").createPage({
                    totalPage: data.totalPage,
                    currPage: data.pageNow,
                    turndown: 'true',
                    backFn: function (p) {
                        page = p;
                        doAjax();
                    }
                });
            }
        }
    })
}

$(function () {
    doAjax()
})

//查询
$('#refer').click(function () {
    page = 1;
    doAjax();
})

